import allure
from selenium.webdriver.common.by import By

from base.base_page import BasePage


class PageLogin(BasePage):

    # BasePage有这些成员变量
    # def __init__(self,driver,action):
    #     self.__driver = driver
    #     self.__action = action

    # 点击登录,回到登录页面
    @allure.step(title="点击登录，回到登录页面")
    def __click_mouse(self):
        self.__action.click(self.__driver.find_element(By.XPATH,"//a[contains(text(),'登录')]")).perform()
    # 输入用户名
    @allure.step(title="输入用户名")
    def __input_username(self,username):
        # self.__driver.find_element(By.CSS_SELECTOR,'#username').send_keys(username)
        self.input_page_element((By.CSS_SELECTOR,'#username'),username)
    # 输入密码
    @allure.step(title="输入密码")
    def __input_password(self,password):
        # self.__driver.find_element(By.CSS_SELECTOR,'#password').send_keys(password)
        self.input_page_element((By.CSS_SELECTOR,'#password'),password)

    # 输入验证码
    @allure.step(title="输入验证码")
    def __input_verify_code(self,verify_code):
        # self.__driver.find_element(By.CSS_SELECTOR,'#verify_code').send_keys(verify_code)
        self.input_page_element((By.CSS_SELECTOR,'#verify_code'),verify_code)

    @allure.step(title="获取登录成功文本值")
    def get_login_success_text(self):
        return self.get_page_element_text((By.CSS_SELECTOR,".mu-m-phone"))

    # 登录失败的文本值
    @allure.step(title="获取登录失败文本值")
    def get_login_fail_text(self):
        return self.get_page_element_text((By.CSS_SELECTOR,".layui-layer-content.layui-layer-padding"))

    # 将登录封装成方法，也可以将上面的方法全写在一个方法中
    @allure.step(title="登录")
    def login(self,username,password,verify_code):
        # self.__click_mouse()
        self.__input_username(username)
        self.__input_password(password)
        self.__input_verify_code(verify_code)
        self.click_login_button((By.CSS_SELECTOR,"a[name='sbtbutton']"))

